package com.carrot.uaa.infrastructure.kafka;

import com.carrot.common.core.domain.R;
import com.carrot.uaa.entity.KafkaEvent;
import com.carrot.uaa.entity.dto.SmsModelDTO;
import com.carrot.uaa.enums.KafkaTopicEnum;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * 短信消息生产者
 */
@Service
public class SmsProducer implements ISmsProducer{

    @Resource(name="kafkaProducer")
    private IUaaProduce kafkaProducer;

    @Override
    public R sendCaptcha(SmsModelDTO smsModelDto) {
        smsModelDto.setSignName(smsModelDto.getSmsTypeEnum().getSignName());
        smsModelDto.setTemplateCode(smsModelDto.getSmsTypeEnum().getTempCode());

        KafkaEvent kafkaEvent=new KafkaEvent();
        kafkaEvent.setMsg(smsModelDto);
        kafkaEvent.setTopic(KafkaTopicEnum.SMS.getVal());
        return kafkaProducer.send(kafkaEvent);
    }
}
